<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	String imgPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/img" + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>我的账户</title>
    
    <script src="<%=basePath%>js/fontSize.js"></script>
    <script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
    
    <script src="<%=basePath%>plugins/ajaxfileupload/ajaxfileupload.js"></script>
    
    <link rel="stylesheet" href="<%=basePath%>css/style.css"/>
    <link rel="stylesheet" href="<%=basePath%>css/style2.css"/>
    
    <link rel="stylesheet" href="<%=basePath%>plugins/layer/mobile/need/layer.css"/>
    <script src="<%=basePath%>plugins/layer/mobile/layer.js"></script>
    <style>
		body{ background:#F5F5F6;}
		.file_head {
		  cursor: pointer;
		  display: block;
		  height: 3rem;
		  opacity: 0;
		  position: absolute;
		  width: 90%;
		}
	</style>
	<script src="<%=basePath%>js/swiper.min.js"></script>
</head>

<body>

  <header class="header3 padding-lr1 background6">
    <p class="header3-left"><a href="<%=basePath%>member/index"><span class="ico bgico-7" style="background-image: url(<%=basePath%>images/img25.png)"></span></a></p>
    <h2 class="header3-title text-align-center color1">我的寻宝</h2>
    <div class="header3-right">
      <figure class="dolamr">
      
        <div class="dolamr-zksq color1">
          <img src="<%=basePath%>images/img27.png">
          <figcaption>导航</figcaption>
        </div>
        
        <div class="dolamr-ajkf">
          <ul>
            <li><a href="###"><span class="ico bgico-12" style="background-image: url(<%=basePath%>images/img38.png)"></span><samp>首页</samp></a></li>
            <li><a href="###"><span class="ico bgico-12" style="background-image: url(<%=basePath%>images/img39.png)"></span><samp>我的</samp></a></li>
            <li><a href="###"><span class="ico bgico-12" style="background-image: url(<%=basePath%>images/img40.png)"></span><samp>分享</samp></a></li>
          </ul>
        </div>
      </figure>
    </div>
    
    <div class="clear-both"></div>
  </header>
  <!--/头部1-->
  <div class="yf-user-set">
  	<a href="javascript:void(0)" class="yf-user-list clearfix" id="upload_a">
  		<input type="file" name="file" id="file_head" class="file_head" onchange="javascript:setImagePreview();" />
        <i class="fl"></i>
        <span class="fl">设置用户头像</span>
        <span class="fr" style="line-height:1.8rem;height:3rem;overflow:hidden;">
        	<c:choose>
				<c:when test="${empty member.avatar}">
					<img src="<%=basePath%>images/img51.png" id="preview" style="border-radius:50%;height:2.2rem;width:2.2rem;float:left;margin-right:0.4rem;margin-top:0.4rem;">
				</c:when>
				<c:otherwise>
					<img src="${member.avatar}" id="preview" style="border-radius:50%;height:2.2rem;width:2.2rem;float:left;margin-right:0.4rem;margin-top:0.4rem;">
				</c:otherwise>
			</c:choose>
        	<font style="float:left;height:3rem;line-height:3rem;">></font>
        </span>
    </a>
    <a href="<%=basePath%>member/info/name?n=${member.nick_name}" class="yf-user-list clearfix">
        <i class="fl"></i>
        <span class="fl">设置用户昵称</span>
        <span class="fr">${member.nick_name} ></span>
    </a>
    <a href="javascript:void(0)" class="yf-user-list clearfix">
        <i class="fl"></i>
        <span class="fl">已绑定手机号${member.phone}</span>
        <span class="fr"></span>
    </a>
    <a href="<%=basePath%>user_setting_password.jsp" class="yf-user-list clearfix">
        <i class="fl"></i>
        <span class="fl">修改登录密码</span>
        <span class="fr"> ></span>
    </a>
    <a href="<%=basePath%>member/info/age?age=${member.age}" class="yf-user-list clearfix">
        <i class="fl"></i>
        <span class="fl">年龄</span>
        <span class="fr">${member.age} ></span>
    </a>
    <a href="<%=basePath%>member/info/education?e=${member.education}" class="yf-user-list clearfix">
        <i class="fl"></i>
        <span class="fl">学历</span>
        <span class="fr">${member.education_txt} ></span>
    </a>
    <a href="<%=basePath%>member/info/salary?s=${member.salary}" class="yf-user-list clearfix">
        <i class="fl"></i>
        <span class="fl">收入情况</span>
        <span class="fr">${member.salary_txt} ></span>
    </a>
    <%-- <a href="#" class="yf-user-list clearfix">
        <i class="fl"></i>
        <span class="fl">常住城市</span>
        <span class="fr">${member.province}，${member.city}，${member.area} ></span>
    </a> --%>
    <a href="<%=basePath%>member/info/myAddress" class="yf-user-list clearfix">
        <i class="fl"></i>
        <span class="fl">收货地址管理</span>
        <span class="fr"> ></span>
    </a>
    <button class="yf-exit" id="exit_login">退出登录</button>
  </div>

  <!--底部1-->
  <div class="footer-1-height"></div>  
  <c:import url="/static/scan.jsp"></c:import>
  <!--/底部1-->

  <script src="<%=basePath%>js/style.js"></script>
  <script type="text/javascript">
  	$(function() {
  		$("#exit_login").on("click", function(){
  			var ctx = "${pageContext.request.contextPath}";
  			window.location.href = ctx + "/member/logout";
  		});
  	});
  	function setImagePreview() {
        var preview, img_txt, localImag, file_head = document.getElementById("file_head"),
        picture = file_head.value;
        if (!picture.match(/.jpg|.gif|.png|.bmp|.JPEG/i)) return alert("您上传的图片格式不正确，请重新选择！"),!1;
        if (preview = document.getElementById("preview"), file_head.files && file_head.files[0]) {
        	preview.style.display = "block",
            preview.style.width = "2.2rem",
            preview.style.height = "2.2rem",
            preview.src = window.navigator.userAgent.indexOf("Chrome") >= 1 || window.navigator.userAgent.indexOf("Safari") >= 1 ? window.webkitURL.createObjectURL(file_head.files[0]) : window.URL.createObjectURL(file_head.files[0]);  
        } else {
            file_head.select(),
            file_head.blur(),
            img_txt = document.selection.createRange().text,
            localImag = document.getElementById("localImag"),
            localImag.style.width = "2.2rem",
            localImag.style.height = "2.2rem";
            try {
                localImag.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)",
                localImag.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = img_txt
            } catch(f) {
                return alert("您上传的图片格式不正确，请重新选择！"),!1;
            }
            preview.style.display = "none",
            document.selection.empty()
        }
        var li = layer.open({
			type: 2,
			content: '正在更新头像'
		});
        var ctx = "${pageContext.request.contextPath}";
        $.ajaxFileUpload
        (
             {
                 url: ctx+'/uploadFile/avatar',//上传后台路径
                 secureuri:false,
                 fileElementId:"file_head",
                 dataType: 'json',
                 success: function (data, status)
                 {
                	 if(data.code == -1) {
                		 layer.close(li);
                    	 layer.open({
                    		 content: data.msg,
                    		 skin: 'msg',
                    		 time: 2 //2秒后自动关闭
                    	 });
                		 window.location.href = ctx+"/again_login.jsp?page=/member/info";
                	 } else if(data.code == 1) {
                		 $.ajax({
               	  		    type : "post",
               	  		    url : ctx+'/member/setAvatar',
               	  		    dataType:"json",
               	  		  	data: {
               	  		  		avatar : "<%=imgPath%>" + data.url
               		        },
               	  		    success : function(msg) {
               	  		    	layer.close(li);
               	  		    	layer.open({
               	  					content: msg.msg,
               	  					skin: 'msg',
               	  					time: 2 //2秒后自动关闭
               	  				});
               	  		    	if (msg.code == -1) {
               	  		    		window.location.href = ctx+"/again_login.jsp?page=/member/info";
               	  		    	} else if (msg.code == 0) {
	               	  		    	var avatar = "${member.avatar}";
	               	  		    	if (null == avatar || avatar == "") {
	               	  		    		avatar = ctx+"/images/img51.png";
	               	  		    	}
	               	  		    	$("#localImag").attr("src", avatar);
               	  		    	}
               	  		    }
						});
                	 } else {
                		 layer.close(li);
                    	 layer.open({
       	  					content: data.msg,
       	  					skin: 'msg',
       	  					time: 2 //2秒后自动关闭
       	  				 });
                    	 var avatar = "${member.avatar}";
                    	 if (null == avatar || avatar == "") {
                    		 avatar = ctx+"/images/img51.png";
                    	 }
                    	 $("#localImag").attr("src", avatar);
                	 }
                	 
                 },
                 error: function (data, status, e)
                 {
                	 layer.close(li);
                	 layer.open({
                		 content: data.msg,
                		 skin: 'msg',
                		 time: 2 //2秒后自动关闭
                	 });
                	 if(data.code == -1) {
                		 window.location.href = ctx+"/again_login.jsp?page=/member/info";
                	 } else {
                    	 var avatar = "${member.avatar}";
                    	 if (null == avatar || avatar == "") {
                    		 avatar = ctx+"/images/img51.png";
                    	 }
                    	 $("#localImag").attr("src", avatar);
                	 }
                 }
             }
         );
        /* $.ajax({
            url:ctx+'/uploadFile',//上传后台路径
            data:{file:$('#file_head').serialize()},
            type:"POST",
            success:function(){
            	
            }
        }); */
        // return document.getElementById("DivUp").style.display = "block",!0;
    }
  </script>
</body>
</html>